$(document).ready(function() {
    $("#login").click(function() {
  
        $.ajax({
            url: '/AcademiaWellness_1/Controller_Login',
            type: 'POST',
            data: {
                oper: "4",
                usuario:$("#usuario").val(),
                senha:$("#senha").val()
                
            },
            complete: function(e, xhr, result) {
                if (e.readyState == 4 && e.status == 200) {
                    try { //Converte a resposta HTTP JSON em um objeto JavaScript
                        var Obj = eval("(" + e.responseText + ")"); //Combo OS

                    }
                    catch (err) { //
                        // Mostra Aviso
                       alert("erro no login");

                    }
                    if (Obj != null) {
                       
             
                        var data = new Date();
	                data.setDate(data.getDate()+1);
                        setCookie("usuario",Obj[0].usuario,data);
                        setCookie("senha",Obj[0].senha,data);
                        setCookie("senha",Obj[0].id,data);
                        setCookie("adm",Obj[1].administrador,data);
                        
                        window.location.href = "/AcademiaWellness_1/wellness.html";
                        
                        
                        


                    }
                }

            }
        });


    });

});


function setCookie(name, value) {
   var argv = setCookie.arguments;
   var argc = setCookie.arguments.length;
   var expires = (argc > 2) ? argv[2] : null;
   var path = (argc > 3) ? argv[3] : null;
   var domain= (argc > 4) ? argv[4] : null;
   var secure= (argc>5) ? argv[5]: false;
   document.cookie = name+"="+escape(value)+ 
  ((expires==null) ? "": (";  expires= "+ expires.toGMTString())) +
  ((path == null) ? "": ("; path=" + path)) +  
  ((domain==null)? "": ("; domain=" + domain)) +
  ((secure==true)? "; secure": "");
}